package com.example.consumer01.controller;

import com.example.consumer01.client.UserServiceClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class ConsumerController {

    @Autowired
    private UserServiceClient userServiceClient;

    @Autowired
    private SentinelService sentinelService;

    private long i = 0;

    @GetMapping("/hello")
    public String hello() throws InterruptedException {
        return userServiceClient.getUserById(++i);
    }

    @GetMapping("/testSentinel")
    public String testSentinel() throws InterruptedException {
        for (int j = 0; j < 20; j++) {
            sentinelService.testSentinel();
            Thread.sleep(200);
        }
        return "";
    }
}
